package PageLib;
import com.thoughtworks.*;
import com.thoughtworks.selenium.Selenium;
import com.thoughtworks.selenium.DefaultSelenium;
import org.junit.*;
import org.junit.runner.*;
import static org.junit.Assert.*;

public class PageOpn {
	public Selenium browserObj =new DefaultSelenium("localhost",4444,"*chrome","http://www.credomobile.com");
//	public Selenium mission = new DefaultSelenium("localhost",4444,"*firefox","http://www.credomobile.com/Mission/Progressive-Social-Change.aspx");

	
	public  void pgClose()
	{
		browserObj.close();
	}
	public void windowOpn(String url)
	{
		browserObj.start();
		browserObj.open(url);
		browserObj.waitForPageToLoad("2000000");
		browserObj.windowMaximize();

		}

	public boolean clickLink(String link)
	{
		if (browserObj.isElementPresent(link)&& browserObj.isVisible(link))
		{
		browserObj.click(link);
		browserObj.waitForPageToLoad("30000");
	return(browserObj.isElementPresent(link)&& browserObj.isVisible(link));
		}
		else
			System.out.println("Element "+link +" is not present in the page");
	
	return(false);}
	
	public void enterText (String element, String val)
	{
		if (browserObj.isElementPresent(element)&& browserObj.isVisible(element))
		{
			System.out.println("Entering"+ val+ "as input");
		browserObj.type(element, val);
		
		}
		else
			System.out.println("Element "+element +" is not present in the page");
	}
	
	public boolean verifyText(String element, String exp)
	{
		String txt;
		txt=browserObj.getText(element);
		return (exp.equalsIgnoreCase(txt));
		
		
	}
   public  boolean verifyElement(String element)
   {
	  if( browserObj.isElementPresent(element))
	  {
	 System.out.println("Element"+element+"is prensent");
	return(true);
	  }
	  else {
		  System.out.println("Element"+element+"is NOT present");
		return(false)  ;
	  }
	   
	 
   }	


   public boolean ElementPresent(String element)
   {
  browserObj.waitForPageToLoad("30000");
   return(browserObj.isElementPresent("element"));
   //return(true);
   	}  
   public boolean verifyTextPresent(String txt)
   //
   {
	   
	 browserObj.isTextPresent(txt);
	 return(true);
   } 

   public void focusElement(String elmt)
   {
   	
   	browserObj.focus(elmt);
   	}
 public void waitForPageTOLoad(String value)
 
 {
	browserObj.waitForPageToLoad("value") ;

 }
public String getText(String element)
 {String txt;
	txt= browserObj.getText(element);
return(txt);	 
 }
	
public boolean elementVisible(String element1)
{
	if(browserObj.isVisible(element1))
	{
		browserObj.highlight(element1);
		System.out.println("element"+element1+" is visible");
		
	   String txt=getText(element1);
	   System.out.println("text present"+txt+"/");
	   return(true);
	   
	}//end of if
	else 
	{
	System.out.println("element is not visible");
	return(false);
	}
}
//end of method

}//end of class
 
